#include "List.h"

template<class TEntity>
List<TEntity>::List()
{
    first = 0;
    last = 0;                     
}

template<class TEntity>
Node<TEntity>* List<TEntity>::getFirst()
{
    return first;              
}

template<class TEntity>
Node<TEntity>* List<TEntity>::getLast()
{
    return last;              
}

template<class TEntity>
int List<TEntity>::getLength()
{
    return length;    
}

template<class TEntity>
Node<TEntity>* List<TEntity>::getByIndex(int index)
{
    if(length > 0)
    {
        Node<TEntity>* iteration = first;
        for(int i=0; iteration != 0 ;i++)
        {
            if(i == index)
            {
                return iteration;
            }       
            iteration = iteration->getNext();
        }
    }else{
          return 0;
    }      
}

template<class TEntity>
void List<TEntity>::add(TEntity* entityToInsert)
{
    Node<TEntity> *tempNode = new Node<TEntity>();
    tempNode->setData(entityToInsert);
    
    if(first == 0)
    {
         first = tempNode;
         last = tempNode;        
    }else
    {
         last->setNext(tempNode);
         last = tempNode;
    } 
    length++;
}

template<class TEntity>
void List<TEntity>::edit(int index, TEntity* entityToUpdate)
{
     Node<TEntity> *tempNode =  new Node<TEntity>(); 
     tempNode = getByIndex(index);
     tempNode->setData(entityToUpdate); 
}
